<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义过滤器</title>
    <script src="../../lib/angularjs/angular.min.js"></script>
</head>
<body>
    <div ng-app="app01">
        <div ng-controller="ctrl01">
            <b>name--------- ：</b>{{name}}<br/>
            <b>name--reverse ：</b>{{ name | reverse}}<br/>
            <b>name--reverse1：</b>{{ name | reverse1}}<br/>
            <b>name--capitalized：</b>{{ name | capitalized}}<br/>
        </div>
    </div>
    <script>
        (function () {
            /** app **/
            var app01=angular.module("app01",[]);

            /** controller **/
            app01.controller("ctrl01",ctrl01);
            function ctrl01($scope) {
                $scope.name="ksjfo230sldn'vcxuaghae";
            }

            /** filter  **/
            app01.filter("reverse",function () {
                return reverse;
            });
            app01.filter("reverse1",function () {
                return reverse1;
            });
            app01.filter("capitalized",function () {
                return capitalized;
            });
            function reverse(input ,uppercase) {
                var out = [];
                for(var i=0 ; i<input.length; i++){
                    out .push(input.charAt(i))
                }
                if(uppercase){
                    return out.reverse().join("").toUpperCase();
                }else{
                    return out.reverse().join("");
                }
            }
            function reverse1(input) {
                var alphabets=input.split("");
                return alphabets.reverse().join("");
            }
            /** 首字母大写 **/
            function capitalized(input) {
                return input[0].toUpperCase()+input.slice(1);
            }
        }());
    </script>
</body>
</html>